import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
        
		// imgUrl: 'https://xingqiu.zanboon.com/',
		// URL: "https://xingqiu.zanboon.com/",
		// H5URL: "https://xingqiuh5.zanboon.com/",
		
		imgUrl: 'https://lightplanet.tuanhaoke.cn/',
		H5URL: "https://lightplaneth5.tuanhaoke.cn/",
		URL: "https://lightplanet.tuanhaoke.cn/", 
		avatarUrl: '',
		nickName: '',
		token: '',
		isAuthorization: false,
		userId: '',
		isAuthorization: false,
		// 每日解谜答错一次是否可以再次答题
		canRiddleAgain: false,
		// 每日解谜成功，奖励是否能翻倍
		canDoublePrize: false,
		// 用户手机号码
		phone: null,
		mqttData: {
			hostname: '',
			password: '',
			topic: '',
			username: ''
		},
		is_can_jin: 1,
		// 分享人的id
		share_id: '',
		formJin: 0,//1是来自金榜题名内的分享，2是来自其他页面的分享,0是自己注册
		inviteNum: 5//邀请人数成为队长
	},
	getters:{
		getNum(state){
			return state.inviteNum
		},
		getCanJin(state) {
			return state.is_can_jin
		},
		getFormJin(state) {
			return state.formJin
		},
		getShareId(state) {
			return state.share_id
		},
		getMqttData(state) {
			return state.mqttData
		},
		getPhone(state,phone) {
			if(state.phone!=null) {
				return state.phone;
			}else {
				return uni.getStorageSync('phone');
			}
		},
		getUrl(state){
			return state.URL;
		},
		getToken(state){
			console.log(state.token)
			console.log(uni.getStorageSync('token'))
			if(state.token) {
				return state.token;
			}else {
				return uni.getStorageSync('token');
			}
		},
		getUserId:function(state) {
			if(state.userId!='') {
				return state.userId
			}else {
				return uni.getStorageSync('userId');
			}
		}
	},
	mutations:{
		updataCanJin(state,is_can_jin) {
			state.is_can_jin = is_can_jin
		},
		updataFromJin(state,formJin) {
			state.formJin = formJin
		},
		updataShareId(state,share_id) {
			state.share_id = share_id
		},
		updataMqttData(state,mqttData) {
			state.mqttData = mqttData
		},
		updataPhone(state,phone) {
			state.phone = phone
		},
		updataCanDoublePrize(state,canDoublePrize) {
			state.canDoublePrize = canDoublePrize
		},
		updataTodayRidd(state,canRiddleAgain) {
			state.canRiddleAgain = canRiddleAgain
		},
		updataToken(state,token){
			uni.setStorage({
				key: 'token',
				data: token,
				success: function () {
				}
			});
			state.token = token;
			state.isAuthorization = true;
			console.log("updataTokenupdataTokenupdataTokenupdataTokenupdataToken")
		},
		updataUserId(state,userId){
			state.userId = userId;
		},
		updataUserInfo(state,info){
			if (info.account_id) {
				state.account_id = account_id
			}
			uni.setStorage({
				key: 'nickName',
				data: info.nickName,
				success: function () {
				}
			});
			uni.setStorage({
				key: 'avatarUrl',
				data: info.avatarUrl,
				success: function () {
				}
			});
			state.nickName = info.nickName;
			state.avatarUrl = info.avatarUrl;
		},
	}
})
export default store
